﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sita.Data.Repositories;
using Sita.Entities;

namespace Sita.MainModule.Services
{
    public class ProviderService
    {
        ProviderRepository ProviderRepository;

        public ProviderService()
        {
            ProviderRepository = new ProviderRepository();
        }

        public IList<Provider> GetAllByBusinessUnitID(int buID)
        {
            return ProviderRepository.GetAllByBusinessUnitID(buID);
        }

        public IList<Provider> GetPaginatedProvidersByBussinesUnitID(int businessUnitID, int pageIndex, int pageSize, string sortColumn, bool ascending, out int totalRows)
        {
            return ProviderRepository.GetPaginatedByBusinessUnitID(businessUnitID, pageIndex, pageSize, sortColumn, ascending, out totalRows);
        }

        public int AddProvider(Provider provider)
        {
            ProviderRepository.Add(provider);

            ProviderRepository.StoreContext.Commit();

            return provider.ProviderID;
        }

        public Provider GetProviderByID(int providerID)
        {
            return ProviderRepository.GetByID(providerID);
        }

        public bool ModifyProvider(Provider provider)
        {
            ProviderRepository.Modify(provider);

            ProviderRepository.StoreContext.Commit();

            return true;
        }

        public Provider GetProviderByIDWithReplacements(int providerID)
        {
            return ProviderRepository.GetByIDWithReplacements(providerID);
        }

        public bool DeleteProvider(Provider provider)
        {
            ProviderRepository.Delete(provider);

            ProviderRepository.StoreContext.Commit();

            return true;
        }
    }
}
